﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SBLib.Common
{
   public static class FileFolderFunc
    {
        public static void DeleteALLFiles_ForTheDerectory(string prmDirectoryPath, string prmSarchPatter)
        {
            try
            {
                foreach (string item in Directory.GetFiles(prmDirectoryPath, prmSarchPatter))
                {
                    File.Delete(item);
                }
            }
            catch (Exception)
            {

            }

        }


        //Delete older files from a directory
        public static void DeleteOldFiles(string prmDirectoryPath, int prmHowmanyDaysOld, string prmSarchPatter)
        {
            try
            {

                foreach (string item in Directory.GetFiles(prmDirectoryPath, prmSarchPatter))
                {
                    FileInfo fi = new FileInfo(item);

                    //check for file create date
                    if (fi.CreationTime < DateTime.Now.AddDays(-1))
                    {
                        try
                        {
                            File.Delete(item);
                        }
                        catch (Exception)
                        { }

                    }

                }
            }
            catch (Exception)
            {

            }

        }


        //Move all files from one directory to another
        public static void MoveALLFiles_FromOneDirectoryToAnother(string prmFromDirectoryPath, string prmToDirectoryPath, string prmSarchPatter)
        {
            try
            {
                foreach (string item in Directory.GetFiles(prmFromDirectoryPath, prmSarchPatter))
                {
                    FileInfo fi = new FileInfo(item);
                    try
                    {
                        File.Move(item, Path.Combine(prmToDirectoryPath, fi.Name));
                    }
                    catch (Exception)
                    { }

                }
            }
            catch (Exception)
            {

            }

        }


        //Copy all files from one directory to another
        public static void CopyALLFiles_FromOneDirectoryToAnother(string prmFromDirectoryPath, string prmToDirectoryPath, string prmSarchPatter)
        {
            try
            {
                foreach (string item in Directory.GetFiles(prmFromDirectoryPath, prmSarchPatter))
                {
                    FileInfo fi = new FileInfo(item);
                    try
                    {
                        File.Copy(item, Path.Combine(prmToDirectoryPath, fi.Name));
                    }
                    catch (Exception)
                    { }

                }
            }
            catch (Exception)
            {

            }

        }
    }
}
